﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace SIN.Client.Controller
{
    class addonInfoController
    {
        public void checkAddonInfo(string aAddonName)
        {
            string aPath = Program.addonInfoModel.addonIdentifierPath(aAddonName);
            if (System.IO.File.Exists(aPath))
            {
                this.parseAddonInfo(aAddonName);
            }
            else
            {
                Program.mainForm.getAddonInfo();
            }
        }

        public void parseAddonInfo(string aAddonName)
        {
            string aPath = Program.addonInfoModel.addonIdentifierPath(aAddonName);
            Program.mainForm.setIdle(true);
            Program.mainForm.setStatus("Start addon information file parsing");

            HtmlDocument aAddonInfoSource = new HtmlDocument();
            aAddonInfoSource.Load(aPath, Encoding.UTF8);

            if (aAddonInfoSource.DocumentNode != null) 
            {
                HtmlNode aAddonLinks = aAddonInfoSource.DocumentNode.SelectSingleNode("//p[@class='buttons']");
                HtmlNodeCollection aAddonTable = aAddonInfoSource.DocumentNode.SelectNodes("//tbody");
                foreach (HtmlNode aAddonItem in aAddonTable)
                {
                    Console.Write(aAddonItem.InnerText);
                }
                    
            }
        }

    }
}
